/**
 * Copyright (c) 2011 The MITRE Corporation. All rights reserved.
 *
 * NOTICE
 * This software was produced for the U. S. Government
 * under Contract No. FA8721-11-C-0001, and is
 * subject to the Rights in Noncommercial Computer Software
 * and Noncommercial Computer Software Documentation Clause
 * (DFARS) 252.227-7014 (JUN 1995)
 */
package org.mitre.edxl.lib;

import java.util.ArrayList;
import java.util.List;

/**
 * Container for EDXL List XML data.
 *
 * @author Danny Gagne
 * @author Rob Gustafson
 * @author Brian Wilkins
 * @author Greg Kern
 */
public class EDXLStringList {

  private static final String DEFAULT_ID_ELEMENTNAME = "valueListUrn";
  private static final String DEFAULT_VALUES_ELEMENTNAME = "value";

  private String listIdElementName;
  private String valuesElementName;

  private String listId;
  private List<String> values;

  /**
   * Initializes a new instance of the EDXLStringList class.
   */
  public EDXLStringList() {
    this("", new ArrayList<String>());
  }

  /**
   * Initializes a new instance of the EDXLStringList class.
   *
   * @param id The list's identifier.
   * @param values The list of the Values.
   */
  public EDXLStringList(String id, List<String> values) {
    this(DEFAULT_ID_ELEMENTNAME, id, DEFAULT_VALUES_ELEMENTNAME, values);
  }

  /**
   * Initializes a new instance of the EDXLStringList class.
   *
   * @param listIdElementName The List Identifier Element Name.
   * @param id The list's identifier.
   * @param valuesElementName The Values Element Name.
   * @param values The list of the Values.
   */
  public EDXLStringList(String listIdElementName, String id,
      String valuesElementName, List<String> values) {
    this.listId = id;
    this.values = values;
    this.listIdElementName = listIdElementName;
    this.valuesElementName = valuesElementName;
  }

  /**
   * Returns a XML representation of the EDXLStringList object.
   *
   * @return A String of the XML representation of the EDXLStringList object.
   */
  public String toXML() {
    String temp = getListIdStartElement() + this.listId + getListIdEndElement();

    for (String val : this.values) {
      temp += getValueStartElement() + val + getValueEndElement();
    }

    return temp;
  }

  /**
   * Adds a Value to the Value list.
   *
   * @param Val The new Value to be added to the list.
   */
  public void addValue(String Val) {
    if (this.values == null) {
      this.values = new ArrayList<String>();
    }
    this.values.add(Val);
  }

  /**
   * Get the value for the List Identifier Start Element.
   *
   * @return The String value of the List Identifier Start Element.
   */
  public String getListIdStartElement() {
    return "<" + this.listIdElementName + ">";
  }

  /**
   * Get the value for the List Identifier End Element.
   *
   * @return The String value of the List Identifier End Element.
   */
  public String getListIdEndElement() {
    return "</" + this.listIdElementName + ">";
  }

  /**
   * Get the value for the Value Start Element.
   *
   * @return The String value of the Value Start Element.
   */
  public String getValueStartElement() {
    return "<" + this.valuesElementName + ">";
  }

  /**
   * Get the value for the Value End Element.
   *
   * @return The String value of the Value End Element.
   */
  public String getValueEndElement() {
    return "</" + this.valuesElementName + ">";
  }

  /**
   * Set the List Identifier Element Name value.
   *
   * @param elementName The value to set the List Identifier Element Name to.
   */
  public void setListIdElementName(String elementName) {
    this.listIdElementName = elementName;
  }

  /**
   * Set the Values Element Name value.
   *
   * @param elementName The value to set the Values Element Name to.
   */
  public void setValuesElementName(String elementName) {
    this.valuesElementName = elementName;
  }

  /**
   * Get the value for the List Identifier.
   *
   * @return The String value of the List Identifier.
   */
  public String getListId() {
    return this.listId;
  }

  /**
   * Set the List Identifier value.
   *
   * @param id The value to set the List Identifier to.
   */
  public void setListId(String id) {
    this.listId = id;
  }

  /**
   * Get the list of the Values.
   *
   * @return The list the Values.
   */
  public List<String> getValues() {
    return this.values;
  }

  /**
   * Set the list of the Values.
   *
   * @param val The list to set the Values to.
   */
  public void setValues(List<String> values) {
    this.values = values;
  }
}
